<%@page import="warehouse.AccountBean"%>
<%@page import="java.sql.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<jsp:useBean id="databaseBean" scope="session" class="warehouse.DatabaseBean"/>    

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>职工列表</title>

<link rel="stylesheet" href="layui/css/layui.css">
<script src="layui/layui.js"></script>
</head>
<body>
<%
	AccountBean account=(AccountBean)session.getAttribute("account");
	if(account==null){
		account = new AccountBean();
	}
%>
	<h1 style="text-align:center">职工列表</h1>
	<span <%=account.getPrivilege()==1?"":"hidden"%>>
	<a href="staff_update_form.jsp" class="layui-btn">
		<i class="layui-icon layui-icon-addition"></i>
		添加新职工
	</a>
	</span>
	<table class="layui-table" lay-even>
		<thead>
		<tr>
			<th>职工号</th>
			<th>姓名</th>
			<th>性别</th>
			<th>年龄</th>
			<th>电话号码</th>
			<th>工作仓库号</th>
			<th>操作</th>
		</tr>
		</thead>
		<%
			String sql=String.format("SELECT staffNo,name,gender,age,telenumber,warehouseNo FROM staff;");
			ResultSet rs=databaseBean.executeQuery(sql);
			while(rs.next()){
				%>
				<tr>
					<td><%=rs.getString("staffNo")  %>	</td>
					<td><%=rs.getString("name")  %>		</td>
					<td><%="M".equals(rs.getString("gender"))?"男":"女"%></td>
					<td><%=rs.getString("age")  %>		</td>
					<td><%=rs.getString("telenumber")  %>		</td>
					<td><%=rs.getString("warehouseNo") %></td>
					<td>
						<a href="warehouse.jsp?warehouseNo=<%=rs.getString("warehouseNo")%>" class="layui-btn">
						查看工作仓库详情
						</a>
						
						<span <%=account.getPrivilege()==1?"":"hidden"%>>
						<a href="staff_update_form.jsp?staffNo=<%=rs.getString("staffNo")%>" class="layui-btn">
						<i class="layui-icon layui-icon-edit"></i>
						修改
						</a>
						<a href="staff_update.jsp?staffNo=-<%=rs.getString("staffNo")%>" class="layui-btn">
						<i class="layui-icon layui-icon-delete"></i>
						删除
						</a>
						</span>
					</td>
				</tr>		
				<%
			}
			rs.close();
			%>
	</table>
</body>
</html>